<?php
namespace admin\controllers;

use common\models\Recommend;
use Yii;


/**
 * 推荐位管理
 */
class RecommendController extends BaseController
{
    public $modelClass = 'common\models\Recommend';
    public $searchModelClass = 'admin\models\RecommendSearch';
    

    /**
     * 置顶
     */
    public function actionUp()
    {
        $id = Yii::$app->request->get('id');

        $recommends = Recommend::find();
        foreach ($recommends->each() as $recommend) {
            if ($recommend->id == $id) { //如果是置顶的分类
                $recommend->display_order = 255;
            } else {
                $recommend->display_order > 0 ?  $recommend->display_order -= 1 :  $recommend->display_order;
            }
            $recommend->save();
        }

        $this->back();
    }
}
